<template>
  <div class="news">
    <!-- 头部 -->
    <van-nav-bar
      style="background-color:#f2f2f2"
      :title="pageTitle"
      left-text=""
      right-text=""
      left-arrow
      @click-left="onClickLeft"
    />
    <!-- 通知 -->
    <van-cell
      is-link
      v-for="(item, index) in newsList"
      :key="index"
      @click="toNewsDetails(item)"
    >
      <i style="color:#ff8917">{{ item.myshijian }}</i> {{ item.mybiaoti }}
      <template #right-icon>
        <van-icon name="arrow" style="line-height: inherit;" />
      </template>
    </van-cell>
    <!-- 数据为空 -->
    <van-empty v-if="newsList.length === 0" description="暂时没有数据" />
  </div>
</template>

<script>
import SERVE from "@/axios/index";
export default {
  name: "news",
  data() {
    return {
      newsList: [], //列表
      pageTitle: "活动列表", // 标题
    };
  },
  mounted() {
    this.pageTitle = this.$route.query.id == "11" ? "活动列表" : "帮助中心";
    this.getNews();
  },
  methods: {
    // 获取news
    getNews() {
      this.$toast.loading({
        mask: true,
        duration: 0,
        message: "加载中...",
      });
      SERVE.getNews({
        params: {
          cs_shuliang: 100, //数量
          cs_lxid: this.$route.query.id, //类型id
        },
      })
        .then((res) => {
          this.$toast.clear();
          this.newsList = res.data;
        })
        .catch((err) => {
          this.$toast.clear();
          console.log("err", err);
        });
    },
    onClickLeft() {
      this.$router.push("/index");
    },
    // 去详情页面
    toNewsDetails(item) {
      // itemId 获取详情的id
      // id 路由标志的id
      this.$router.push({
        path: "/newsDetails",
        query: { itemId: item.myid, id: this.$route.query.id },
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
